package factory_pattern.calculator01;


import java.util.Scanner;

/**
 * @Author xiumu
 * @Date 2019/2/26 21:20
 * 简易计算器第一代版本
 */
public class Calculator {
    public static void main(String[] args) {
        System.out.println("请输入第一个数字：");
        Scanner input = new Scanner(System.in);
        double firstNumber = input.nextDouble();
        System.out.println("请输入运算符：");
        String operator = input.next();
        char oper = operator.charAt(0);
        System.out.println("请输入第二个数字：");
        double secondNumber = input.nextDouble();
        input.close();

        //计算业务
        double result = Operator.calculate(firstNumber, secondNumber, oper);

        System.out.println("运算结果为：");
        System.out.println(firstNumber + "+" + secondNumber+"="+result);
    }

    public static void calculator01() {
        System.out.println("请输入第一个数字：");
        Scanner input = new Scanner(System.in);
        double firstNumber = input.nextDouble();
        System.out.println("请输入运算符：");
        String operator = input.next();
        char oper = operator.charAt(0);
        System.out.println("请输入第二个数字：");
        double secondNumber = input.nextDouble();
        input.close();
        System.out.println("运算结果为：");
        switch (oper){
            case '+':
                System.out.println(firstNumber + "+" + secondNumber+"="+(firstNumber+secondNumber));
                break;
            case '-':
                System.out.println(firstNumber + "-" + secondNumber+"="+(firstNumber-secondNumber));
                break;
            case '*':
                System.out.println(firstNumber + "*" + secondNumber+"="+(firstNumber*secondNumber));
                break;
            case '/':
                if (secondNumber==0){
                    System.out.println("输入不合法");
                    break;
                }
                System.out.println(firstNumber + "/" + secondNumber+"="+(firstNumber/secondNumber));
                break;
        }
    }
}
